const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const WeatherCache = sequelize.define('WeatherCache', {
  cache_id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    field: 'cache_id',
  },
  city_id: {
    type: DataTypes.STRING,
    allowNull: false,
    field: 'city_id',
  },
  date: {
    type: DataTypes.DATE,
    allowNull: false,
    field: 'date',
  },
  temperature: {
    type: DataTypes.FLOAT,
    allowNull: false,
    field: 'temperature',
  },
  wind_speed: {
    type: DataTypes.FLOAT,
    allowNull: false,
    field: 'wind_speed',
  },
  air_quality: {
    type: DataTypes.STRING,
    allowNull: true, // Assuming air_quality can be null
    field: 'air_quality',
  },
  precipitation: {
    type: DataTypes.FLOAT,
    allowNull: true, // Assuming precipitation can be null
    field: 'precipitation',
  },
  weather_condition: {
    type: DataTypes.STRING,
    allowNull: true,
    field: 'weather_condition',
  }
}, {
  tableName: 'weather_cache', // 确保表名与数据库中的一致
  timestamps: false, // 禁用 createdAt 和 updatedAt 字段
});

module.exports = WeatherCache; 